<template> 
    <el-card class="form-container" shadow="never">
        <el-form :model="umsMemberCard" :rules="rules" ref="UmsMemberCardFrom" label-width="150px">


                  <!--
                        <el-form-item
                            label="主键"
                            prop="id">
                        <el-input v-model="umsMemberCard.id" style="width: 370px;"/>
                    </el-form-item>
                   -->


                    <el-form-item
                            label="会员卡编号"
                            prop="cartNo">
                        <el-input v-model="umsMemberCard.cartNo" style="width: 370px;"/>
                    </el-form-item>


                     <el-form-item
                         
                            label="类型"
                            prop="cartCategory">
                        <el-radio-group v-model="umsMemberCard.cartCategory">
                            <el-radio :label="0">次卡</el-radio>
                            <el-radio :label="1">储值卡</el-radio>
                        </el-radio-group>
                    </el-form-item>

                 


                    <el-form-item  v-if="umsMemberCard.cartCategory==1"
                            label="会员卡金额"
                            prop="cart balance">
                        <el-input v-model="umsMemberCard.cartBalance" style="width: 370px;"/>
                    </el-form-item>


                    <el-form-item  v-if="umsMemberCard.cartCategory==0"
                            label="会员卡次数"
                            prop="cartTimes">
                        <el-input v-model="umsMemberCard.cartTimes" style="width: 370px;"/>
                    </el-form-item>

                    <!-- 
                        
                    <el-form-item
                            label="持卡人ID"
                            prop="userId">
                        <el-input v-model="umsMemberCard.userId" style="width: 370px;"/>
                    </el-form-item>
                    -->


                    <el-form-item
                            label="持卡人姓名"
                            prop="username">
                        <el-input v-model="umsMemberCard.username" style="width: 370px;"/>
                    </el-form-item>


                    <el-form-item
                            label="办卡日期"
                            prop="openDate">
                            <el-date-picker
                                type="date"
                                placeholder="选择日期"
                                v-model="umsMemberCard.openDate"
                                style="width: 370px"
                                value-format="yyyy-MM-dd"
                                ></el-date-picker>
                    </el-form-item>


                 <!--
                         <el-form-item
                            label="操作人ID"
                            prop="createBy">
                        <el-input v-model="umsMemberCard.createBy" style="width: 370px;"/>
                    </el-form-item>


                    <el-form-item
                            label="操作人姓名"
                            prop="createName">
                        <el-input v-model="umsMemberCard.createName" style="width: 370px;"/>
                    </el-form-item>


                    <el-form-item
                            label="操作日期"
                            prop="createDate">
                        <el-input v-model="umsMemberCard.createDate" style="width: 370px;"/>
                    </el-form-item>


                    <el-form-item
                            label="办卡门店"
                            prop="storeId">
                        <el-input v-model="umsMemberCard.storeId" style="width: 370px;"/>
                    </el-form-item>
                  -->


                    <el-form-item
                            label="办卡门店名称"
                            prop="storeName">
                        <el-input v-model="umsMemberCard.storeName" style="width: 370px;"/>
                    </el-form-item>

                   

                    <el-form-item
                            label="有效期"
                            prop="validityDate">
                        <el-input-number
                            style="width: 370px"
                            v-model="umsMemberCard.validityDate"
                            :controls="true" >
                        </el-input-number>/月
                    </el-form-item>


                    <el-form-item
                            label="服务项目"
                            prop="serviceItem">
                        <el-input v-model="umsMemberCard.serviceItem" style="width: 370px;"/>
                    </el-form-item>


                    <el-form-item
                            label="备注"
                            prop="memo">
                        <el-input v-model="umsMemberCard.memo" style="width: 370px;"/>
                    </el-form-item>


            <el-form-item>
                <el-button type="primary" @click="onSubmit('UmsMemberCardFrom')">提交</el-button>
                <el-button v-if="!isEdit" @click="resetForm('UmsMemberCardFrom')">重置</el-button>
            </el-form-item>
        </el-form>
    </el-card>
</template>
<script>
    import {createUmsMemberCard, getUmsMemberCard, updateUmsMemberCard} from '@/api/ums/umsMemberCard'
    import SingleUpload from '@/components/Upload/singleUpload'

    const defaultUmsMemberCard = {
        name: ''
    };
    export default {
        name: 'UmsMemberCardDetail',
        components: {SingleUpload},
        props: {
            isEdit: {
                type: Boolean,
                default: false
            }
        },
        data() {
            return {
            umsMemberCard:
            Object.assign({},
        defaultUmsMemberCard),
            rules: {
                name: [
                    {required: true, message: '请输入品牌名称', trigger: 'blur'},
                    {min: 2, max: 140, message: '长度在 2 到 140 个字符', trigger: 'blur'}
                ],
                    logo
            :
                [
                    {required: true, message: '请输入品牌logo', trigger: 'blur'}
                ],
                    sort
            :
                [
                    {type: 'number', message: '排序必须为数字'}
                ],
            }
        }
        },
        created() {
            if (this.isEdit) {
                getUmsMemberCard(this.$route.query.id).then(response => {
                    this.umsMemberCard = response.data;
            })
                ;
            } else {
                this.umsMemberCard = Object.assign({},
            defaultUmsMemberCard)
                ;
            }
        },
        methods: {
            onSubmit(formName) {
                this.$refs[formName].validate((valid) => {
                    if(valid) {
                        this.$confirm('是否提交数据', '提示', {
                            confirmButtonText: '确定',
                            cancelButtonText: '取消',
                            type: 'warning'
                        }).then(() => {
                            if(this.isEdit
                    )
                        {
                            updateUmsMemberCard(this.$route.query.id, this.umsMemberCard).then(response => {
                                if(response.code == 200
                        )
                            {
                                this.$refs[formName].resetFields();
                                this.$message({
                                    message: '修改成功',
                                    type: 'success',
                                    duration: 1000
                                });
                                this.$router.back();
                            }
                        else
                            {
                                this.$message({
                                    message: response.msg,
                                    type: 'error',
                                    duration: 1000
                                });
                            }

                        })
                            ;
                        }
                    else
                        {
                            createUmsMemberCard(this.umsMemberCard).then(response => {
                                if(response.code == 200
                        )
                            {
                                this.$refs[formName].resetFields();
                                this.umsMemberCard = Object.assign({},
                            defaultUmsMemberCard)
                                ;
                                this.$message({
                                    message: '提交成功',
                                    type: 'success',
                                    duration: 1000
                                });
                                this.$router.back();
                            }
                        else
                            {
                                this.$message({
                                    message: response.msg,
                                    type: 'error',
                                    duration: 1000
                                });
                            }

                        })
                            ;
                        }
                    })
                        ;

                    } else {
                        this.$message({
                            message: '验证失败',
                            type: 'error',
                            duration: 1000
                        });
                return false;
            }
            })
                ;
            },
            resetForm(formName) {
                this.$refs[formName].resetFields();
                this.umsMemberCard = Object.assign({},
            defaultUmsMemberCard)
                ;
            }
        }
    }
</script>
<style>
</style>


